const express = require('express');
const router = express.Router();
const orderController = require('../controllers/order.controller');
const { authMiddleware } = require('../middlewares/auth.middleware');

// 获取当前用户的所有订单
// GET /api/orders
router.get('/', authMiddleware, orderController.getMyOrders);

// 获取订单统计信息
// GET /api/orders/stats
router.get('/stats', authMiddleware, orderController.getOrderStats);

// 创建新订单
// POST /api/orders
router.post('/', authMiddleware, orderController.createOrder);

// 获取订单详情
// GET /api/orders/:id
router.get('/:id', authMiddleware, orderController.getOrderById);

// 更新订单为已支付状态
// PUT /api/orders/:id/pay
router.put('/:id/pay', authMiddleware, orderController.updateOrderToPaid);

// 申请退款
// POST /api/orders/:id/refund
router.post('/:id/refund', authMiddleware, orderController.requestRefund);

// 取消订单
// PUT /api/orders/:id/cancel
router.put('/:id/cancel', authMiddleware, orderController.cancelOrder);

// 更新订单状态
// PUT /api/orders/:id/status
router.put('/:id/status', authMiddleware, orderController.updateOrderStatus);

module.exports = router; 